import 'package:mybase/base/tool/pprint/FFLog.dart';
import 'package:torch_light/torch_light.dart';

///闪光灯控制
class PhoneFlashUtil {
  ///闪光灯是否可用
  static Future<bool> isAvalable() async {
    try {
      return await TorchLight.isTorchAvailable();
    } on Exception catch (_) {
      FFLog.info("闪光灯不可使用");
    }

    return false;
  }

  ///打开闪光灯
  static Future<bool> open() async {
    try {
      await TorchLight.enableTorch();
      return true;
    } on Exception catch (_) {
      FFLog.info("闪光灯打开失败");
    }
    return false;
  }

  ///关闭闪光灯
  static Future<bool> close() async {
    try {
      await TorchLight.disableTorch();
      return true;
    } on Exception catch (_) {
      FFLog.info("闪光灯打开失败");
    }
    return false;
  }
}
